<script setup>
import { transformDuration } from '@/utils'
import { useRouter, useRoute } from 'vue-router'

const $router = useRouter()
const $route = useRoute()

const props = defineProps(['courses'])
</script>

<template>
  <div class="courses">
    <div class="course" v-for="item in courses" @click="$router.replace(`/courses/${item.id}?from=${$route.fullPath}`)">
      <div class="image">
        <img :src="item.image" />
        <img class="icon-play" src="@/assets/img/play.png" />
      </div>
      <div class="label">{{ item.name }}{{ item.name }}{{ item.name }}</div>
      <div class="duration">{{ transformDuration(item.duration, true) }}</div>
    </div>
  </div>
</template>

<style lang="scss" scoped>
.courses {
  display: flex;
  flex-wrap: wrap;
  padding: 0 3.2vw 0.8vw 0.8vw;
  .course {
    margin-left: 2.4vw;
    margin-top: 3.2vw;
    width: 45.6vw;
    background: #fff;
    border-radius: 6px;
    padding: 1.07vw 1.07vw 2.8vw 1.07vw;
    .image {
      height: 24.45vw;
      border-radius: 6px;
      display: flex;
      align-items: center;
      justify-content: center;
      overflow: hidden;
      position: relative;
      background: #f7f8fa;
      img {
        display: block;
        max-width: 100%;
        max-height: 100%;
      }
    }

    .duration {
      line-height: 1;
      font-family: PingFangSC-Regular;
      font-size: 2.6vw;
      color: rgba(0, 0, 0, 0.4);
      letter-spacing: 0;
      font-weight: 400;
      margin-top: 1vw;
    }

    .label {
      font-size: 3.5vw;
      margin-top: 1vw;
      overflow: hidden;
      text-overflow: ellipsis;
      font-family: PingFangSC-Regular;
      color: rgba(0, 0, 0, 0.9);
      letter-spacing: 0;
      font-weight: 400;
      white-space: nowrap;
    }
  }
}

.icon-play {
  position: absolute;
  right: 1.8vw;
  top: 1.8vw;
  width: 4.8vw;
}
</style>
